package org.come.control;

import java.math.BigDecimal;
import java.util.List;

import org.come.Frame.*;
import org.come.Jpanel.NewRefiningJpanel;
import org.come.Jpanel.RefiningEquiJpanel;
import org.come.Jpanel.WashJpanel;
import org.come.MountShouHu.ShouhuPackJframe;
import org.come.action.FromServerAction;
import org.come.bean.QualityClBean;
import org.come.entity.Goodstable;
import org.come.lianhua.AutoMaticRefiningJframe;
import org.come.starcard.JframeStarCardMain;
import org.come.summonequip.JframeReclaimSkillMain;
import org.come.summonequip.JframeSummonEquipMain;
import org.come.summonequip.JpanelSummonEquipMain;
import org.come.until.AccessSuitMsgUntil;
import org.come.until.FormsManagement;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.GsonUtil;

import com.tool.btn.BaptizeBtn;
import com.tool.role.RoleData;
import com.tool.role.RoleProperty;

public class ExtraAttrOperControl implements FromServerAction {

    @Override
    public void controlMessFromServer(String mes, String type) {
        // 依据协议头进行划分方法
        // String mesProcess[] = mes.split("//");
        if ("extrattroper".equals(type)) {
            QualityClBean clBean = GsonUtil.getGsonUtil().getgson().fromJson(mes, QualityClBean.class);
            if (clBean == null) {
                return;
            }
            AutoMaticRefiningJframe.getAssistantJframe().getAssistantJpanel().detectionProperties(clBean);
            switch (clBean.getType()) {
            case 1: // 炼化
                NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel().ew(clBean);
                break;
            case 2: // 炼器
            case -2: // 直接替换炼器
                NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel().ew(clBean);
                System.out.println(clBean.getNewAttr());
                break;
            case 3: // 神兵
                break;
            case 4: // 套装洗炼
                suitXl(clBean.getNewAttr());
                BaptizeBtn.setNewEx(clBean.getNewAttr());
                break;
            case -4: // 直接替换新属性
                changeAttr(clBean.getNewAttr());
                if (clBean.getNewAttr() != null && clBean.getNewAttr() != "") {
                    Goodstable goodstable = WashJpanel.getGoodstableBean().getGoodstable();
                    if (goodstable == null) {
                        return;
                    }
                    String[] ss = goodstable.getValue().split("\\|");
                    // 替换属性
                    String value = BaptizeBtn.newExtra(ss, 3, clBean.getNewAttr());
                    goodstable.setValue(value);
                }
                break;
            case 5: // 直接替换宝石属性
                Goodstable good = GoodsListFromServerUntil.getRgid(clBean.getRgid());
                if (good != null) {
                    // 替换属性
                    String value = BaptizeBtn.newExtra(good.getValue().split("\\|"), 4, clBean.getNewAttr());
                    good.setValue(value);
                    // GemstoneBtn.GETNEWS(good);
                    GemMakeFrame.getGemMakeFrame().getJpanel().optionClick(good);
                    if (good.getStatus() == 1) {
                        RoleProperty.getRoleProperty().equipWearOff();
                    }
                }
                break;
            case 44: // 召唤兽装备重洗技能
                if (JframeSummonEquipMain.getJframeSummonEquipMain().getJpanelSummonEquipMain().getChooseEquip() == null) {
                    return;
                }
                Goodstable chooseEquip = GoodsListFromServerUntil.getRgid(JframeSummonEquipMain
                        .getJframeSummonEquipMain().getJpanelSummonEquipMain().getChooseEquip());
                if (chooseEquip == null) {
                    return;
                }
                if (clBean.getRgid().compareTo(chooseEquip.getRgid()) == 0) {
                    String valuesMessage = JframeSummonEquipMain.getJframeSummonEquipMain().getJpanelSummonEquipMain()
                            .getValuesMessage(chooseEquip.getValue().split("\\|"), "觉醒技");
                    JframeReclaimSkillMain.getJframeReclaimSkillMain().getJpanelReclaimSkillMain()
                            .washSkillViewgetMessage(valuesMessage, 0);
                    JframeReclaimSkillMain.getJframeReclaimSkillMain().getJpanelReclaimSkillMain()
                            .washSkillViewgetMessage(clBean.getNewAttr(), 1);
                    JframeReclaimSkillMain.getJframeReclaimSkillMain().getJpanelReclaimSkillMain()
                            .setQualityClBean(clBean);
                    AutoMaticRefiningJframe.getAssistantJframe().getAssistantJpanel().petEquiDetectionProperties(clBean);
                    if (!JframeReclaimSkillMain.getJframeReclaimSkillMain().isVisible()) {
                        FormsManagement.showForm(94);
                    }
                }
                break;
            case 46:
                JpanelSummonEquipMain jpanelSummonEquipMain = JframeSummonEquipMain.getJframeSummonEquipMain()
                        .getJpanelSummonEquipMain();
                if (jpanelSummonEquipMain.getChooseEquip() == null) {
                    return;
                }
                Goodstable chooseEquip1 = GoodsListFromServerUntil.getRgid(JframeSummonEquipMain
                        .getJframeSummonEquipMain().getJpanelSummonEquipMain().getChooseEquip());
                if (chooseEquip1 == null) {
                    return;
                }
                chooseEquip1
                        .setValue(BaptizeBtn.newExtra(chooseEquip1.getValue().split("\\|"), 5, clBean.getNewAttr()));
                String valuesMessage = JframeSummonEquipMain.getJframeSummonEquipMain().getJpanelSummonEquipMain()
                        .getValuesMessage(chooseEquip1.getValue().split("\\|"), "觉醒技");
                jpanelSummonEquipMain.skillMessage(valuesMessage.split("&"));
                jpanelSummonEquipMain.getNowNumLab().setText(
                        "<html><body>(拥有:<font color=#FFFF00>"
                                + RoleData.getRoleData().getLoginResult().getScoretype("比斗奖章").toString()
                                + "</font>)</body><html>");

                break;
            case 53:
                BigDecimal chooseStarCardId = JframeStarCardMain.getJframeSummonEquipMain().getJpanelStarCardMain()
                        .getChooseStarCardId();
                if (chooseStarCardId == null) {
                    return;
                }
                Goodstable goodstable = GoodsListFromServerUntil.getRgid(chooseStarCardId);
                if (goodstable == null) {
                    return;
                }
                String value = goodstable.getValue().split("\\|")[3];
                NewRefiningJpanel refiningJpanel = NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel();
                if (!NewRefiningJframe.getNewRefiningJframe().isVisible()) {
                    refiningJpanel.show(value, 2, false);
                }
                refiningJpanel.ew(clBean);
                RefiningEquiJpanel EJpanel = WorkshopRefiningJframe.getWorkshopRefiningJframe()
                        .getWorkshopRefiningJpanel().getCardJpanel().getEquiJpanel();
                EJpanel.setType(0);
                break;
            case 54:
                BigDecimal chooseStarCardId2 = JframeStarCardMain.getJframeSummonEquipMain().getJpanelStarCardMain()
                        .getChooseStarCardId();
                if (chooseStarCardId2 == null) {
                    return;
                }
                Goodstable goodstable2 = GoodsListFromServerUntil.getRgid(chooseStarCardId2);
                if (goodstable2 == null) {
                    return;
                }
                String value2 = goodstable2.getValue().split("\\|")[4];
                NewRefiningJpanel refiningJpanel2 = NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel();
                if (!NewRefiningJframe.getNewRefiningJframe().isVisible()) {
                    refiningJpanel2.show(value2, 3, false);
                }
                NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel().ew(clBean);
                break;
            case 71:
            case 72:
            case 73:
            case 74:
            case 75:
            case 76:
                NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel().ew(clBean);
                break;
                case 8:
                    if (clBean.getNewAttr()==null){
                        ZhuFrame.getZhuJpanel().addPrompt2("无默契配饰不可点粹");
                        return;
                    }
                    DdianJframe.getDdianJframe().getDianJpanel().ew(clBean);
                    break;
                case 9:
                    DianQJframe.getDdianQJframe().getDianJpanel().ew(clBean);
                    break;
                case 47:
                    ShouhuPackJframe.getShouhuPackJframe().getShouhuPackJpanel().ew(clBean);
                    break;
            default:
                break;
            }
        }
    }

    /**
     * 套装洗炼
     */
    public void suitXl(String newAttr) {
        // 还原面板
        for (int i = 0; i < 4; i++) {
            SuitBaptizeJframe.getSuitBaptizeJframe().getBaptizeJpanel().getNewAttr()[i].setText("");
            WashJpanel.getLabsx()[i].setText("");
        }
        List<String> attr = AccessSuitMsgUntil.getSuitAttr(newAttr);
        if (attr != null) {
            int index = attr.size() >= 4 ? 4 : attr.size();
            for (int i = 0; i < index; i++) {
                SuitBaptizeJframe.getSuitBaptizeJframe().getBaptizeJpanel().getNewAttr()[i].setText(attr.get(i));
                WashJpanel.getLabsx()[i].setText(attr.get(i));
            }
        }
    }

    /**
     * 直接替换新属性
     */
    public void changeAttr(String newAttr) {
        // 还原面板
        for (int i = 0; i < 4; i++) {
            SuitBaptizeJframe.getSuitBaptizeJframe().getBaptizeJpanel().getOldAttr()[i].setText("");
            SuitBaptizeJframe.getSuitBaptizeJframe().getBaptizeJpanel().getNewAttr()[i].setText("");
            WashJpanel.getLabsx()[i].setText("");
        }
        List<String> attr = AccessSuitMsgUntil.getSuitAttr(newAttr);
        if (attr != null) {
            int index = attr.size() >= 4 ? 4 : attr.size();
            for (int i = 0; i < index; i++) {
                SuitBaptizeJframe.getSuitBaptizeJframe().getBaptizeJpanel().getOldAttr()[i].setText(attr.get(i));
                WashJpanel.getLabsx()[i].setText(attr.get(i));
            }
        }
    }
}
